/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.kj.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeesite.common.lang.DateUtils;
import com.jeesite.common.utils.excel.ExcelExport;
import com.jeesite.modules.kj.entity.KjMember;
import com.jeesite.modules.kj.enums.IntegralEnum;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.kj.entity.KjMemberIntegralHistory;
import com.jeesite.modules.kj.service.KjMemberIntegralHistoryService;

import java.math.BigDecimal;
import java.util.List;

/**
 * kj_member_integral_historyController
 * @author hzy
 * @version 2021-07-04
 */
@Controller
@RequestMapping(value = "${adminPath}/kj/kjMemberIntegralHistory")
public class KjMemberIntegralHistoryController extends BaseController {

	@Autowired
	private KjMemberIntegralHistoryService kjMemberIntegralHistoryService;

	/**
	 * 获取数据
	 */
	@ModelAttribute
	public KjMemberIntegralHistory get(String id, boolean isNewRecord) {
		return kjMemberIntegralHistoryService.get(id, isNewRecord);
	}

	/**
	 * 查询列表
	 */
	@RequiresPermissions("kj:kjMemberIntegralHistory:view")
	@RequestMapping(value = {"list", ""})
	public String list(KjMemberIntegralHistory kjMemberIntegralHistory, Model model) {
		model.addAttribute("kjMemberIntegralHistory", kjMemberIntegralHistory);
		return "modules/kj/kjMemberIntegralHistoryList";
	}

	/**
	 * 查询列表
	 */
	@RequiresPermissions("kj:kjMemberIntegralHistory:view")
	@RequestMapping(value = {"contributeList", ""})
	public String contributeList(KjMemberIntegralHistory kjMemberIntegralHistory, Model model) {
		model.addAttribute("kjMemberIntegralHistory", kjMemberIntegralHistory);
		return "modules/kj/kjMemberIntegralHistoryContributeList";
	}


	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("kj:kjMemberIntegralHistory:view")
	@RequestMapping(value = "contributeListData")
	@ResponseBody
	public Page<KjMemberIntegralHistory> contributeListData(KjMemberIntegralHistory kjMemberIntegralHistory, HttpServletRequest request, HttpServletResponse response) {
		kjMemberIntegralHistory.setIntegral_lte(BigDecimal.ONE.negate());
		kjMemberIntegralHistory.setIntegralType_In(IntegralEnum.CONTRIBUTE.getType(),IntegralEnum.TEAMCONTRIBUTE.getType());
		kjMemberIntegralHistory.setPage(new Page<>(request, response));
		Page<KjMemberIntegralHistory> page = kjMemberIntegralHistoryService.findPage(kjMemberIntegralHistory);
		return page;
	}
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("kj:kjMemberIntegralHistory:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<KjMemberIntegralHistory> listData(KjMemberIntegralHistory kjMemberIntegralHistory, HttpServletRequest request, HttpServletResponse response) {
		kjMemberIntegralHistory.setPage(new Page<>(request, response));
		Page<KjMemberIntegralHistory> page = kjMemberIntegralHistoryService.findPage(kjMemberIntegralHistory);
		return page;
	}

	/**
	 * 查询发放数据修改列表
	 */
	@RequiresPermissions("kj:kjMemberJob:edit")
	@RequestMapping(value = "editList")
	@ResponseBody
	public List<KjMemberIntegralHistory> editList(KjMemberIntegralHistory kjMemberIntegralHistory, HttpServletRequest request, HttpServletResponse response) {
		kjMemberIntegralHistory.setPage(new Page<>(request, response));
		List<KjMemberIntegralHistory> page = kjMemberIntegralHistoryService.findList(kjMemberIntegralHistory);
		return page;
	}


	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("kj:kjMemberIntegralHistory:view")
	@RequestMapping(value = "form")
	public String form(KjMemberIntegralHistory kjMemberIntegralHistory, Model model) {
		model.addAttribute("kjMemberIntegralHistory", kjMemberIntegralHistory);
		return "modules/kj/kjMemberIntegralHistoryForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("kj:kjMemberIntegralHistory:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated KjMemberIntegralHistory kjMemberIntegralHistory) {
		kjMemberIntegralHistoryService.save(kjMemberIntegralHistory);
		return renderResult(Global.TRUE, text("保存kj_member_integral_history成功！"));
	}

	/**
	 * 删除数据
	 */
	@RequiresPermissions("kj:kjMemberIntegralHistory:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(KjMemberIntegralHistory kjMemberIntegralHistory) {
		kjMemberIntegralHistoryService.delete(kjMemberIntegralHistory);
		return renderResult(Global.TRUE, text("删除kj_member_integral_history成功！"));
	}

	/**
	 * 导出捐赠数据
	 */
	@RequiresPermissions("kj:kjMemberIntegralHistory:view")
	@RequestMapping(value = "exportContributeData")
	public void exportContributeData(KjMemberIntegralHistory history, Boolean isAll, String ctrlPermi, HttpServletResponse response) {
		history.setIntegral_lte(BigDecimal.ONE.negate());
		List<KjMemberIntegralHistory> list = kjMemberIntegralHistoryService.findList(history);
		String fileName = "捐赠数据" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
		try(ExcelExport ee = new ExcelExport("捐赠数据", KjMemberIntegralHistory.class)){
			ee.setDataList(list).write(response, fileName);
		}
	}
}
